package com.usabb.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.ifast.common.base.CoreServiceImpl;
import com.usabb.dao.CombosCategoryItemDao;
import com.usabb.domain.CombosCategoryItemDO;
import com.usabb.service.CombosCategoryItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;


import java.util.List;


@Slf4j
@Service
public class CombosCategoryItemServiceImpl extends CoreServiceImpl<CombosCategoryItemDao, CombosCategoryItemDO> implements CombosCategoryItemService {


    @Override
    public List<CombosCategoryItemDO> getByCategoryId(Long categoryId) {
        Wrapper<CombosCategoryItemDO> wrapper = generateWrapper(categoryId);

        return this.selectList(wrapper);
    }

    @Override
    public boolean deleteByCategoryId(Long categoryId) {
        Wrapper<CombosCategoryItemDO> wrapper = generateWrapper(categoryId);

        return this.delete(wrapper);
    }


    private static Wrapper<CombosCategoryItemDO> generateWrapper(Long categoryId) {
        CombosCategoryItemDO itemDO = new CombosCategoryItemDO();
        itemDO.setCategoryId(categoryId);
        return new EntityWrapper<>(itemDO).orderBy("id", false);
    }
}
